import matplotlib.pyplot as plt
import numpy as np

# 图4.1 不同算法在4-Room环境中的性能对比
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))

# 数据准备
algorithms = ['FF', 'DQN', 'A3C', 'H-DRL\n(w/o Attn)', 'AH-DRLP\n(Ours)']
success_rate = [65, 72, 80, 85, 95]  # 成功率 (%)
average_steps = [28, 25, 22, 20, 18] # 平均步数 (越少越好)

x = np.arange(len(algorithms))

# 左图：成功率
bars1 = ax1.bar(x, success_rate, color=['grey', 'lightblue', 'lightgreen', 'orange', 'coral'])
ax1.set_title('(a) 规划成功率对比', fontproperties='SimHei', fontsize=12)
ax1.set_ylabel('成功率 (%)', fontproperties='SimHei')
ax1.set_xticks(x)
ax1.set_xticklabels(algorithms, fontproperties='SimHei')
# 在柱子上添加数值
for bar in bars1:
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 1, f'{height}%', ha='center', va='bottom')

# 右图：平均步数
bars2 = ax2.bar(x, average_steps, color=['grey', 'lightblue', 'lightgreen', 'orange', 'coral'])
ax2.set_title('(b) 平均路径长度对比', fontproperties='SimHei', fontsize=12)
ax2.set_ylabel('平均步数', fontproperties='SimHei')
ax2.set_xticks(x)
ax2.set_xticklabels(algorithms, fontproperties='SimHei')
# 在柱子上添加数值
for bar in bars2:
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 0.2, f'{height}', ha='center', va='bottom')

plt.suptitle('图4.1 不同算法在4-Room环境中的性能对比', fontproperties='SimHei', fontsize=14)
plt.tight_layout()
plt.show()